package com.yjian.controller;

import com.yjian.service.PayLogService;
import com.yjian.auth.AuthService;
import com.yjian.common.SDataResult;
import com.yjian.controller.bean.GetMemberPayLogPartRequest;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * Created by xuxiaobao on 2017/9/29.
 */
@Log4j
@RestController
@RequestMapping("/api/log")
public class PayLogController {
    @Autowired
    private PayLogService payLogService;

    @Autowired
    private AuthService authService;

    @ApiOperation(value = "获取会员最近几次消费记录", notes = "获取会员最近几次消费记录（2条）")
    @PostMapping("/v1/part")
    public Object getMemberPayLogPart(@Valid @RequestBody GetMemberPayLogPartRequest request,
                                      HttpServletRequest httpServletRequest) {
        try {
            String uid = authService.getUidFromRequestHeader(httpServletRequest);
            return payLogService.getMemberPayLogPart(uid,request.getMid());
        } catch (Exception e) {
            outPutErrorLog(e);
            log.info("获取会员最近几次消费记录:{}"+e.getMessage());
        }
        return SDataResult.fail();
    }

    private void outPutErrorLog(Exception e) {
        System.out.println(e.getMessage());
    }
}
